package com.heiye.relation.biz.rpc;

import cn.hutool.core.collection.CollUtil;
import com.heiye.framework.common.response.Response;
import com.heiye.user.api.api.UserFeignApi;
import com.heiye.user.api.dto.req.FindUsersByIdsReqDTO;
import com.heiye.user.api.dto.resp.FindUserByIdRspDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author: heiye
 * @date: 2025/07/17 下午2:25
 * @version: v1.0.0
 * @description: Rpc: 用户服务
 */
@Component
public class UserRpcService {

    @Resource
    private UserFeignApi userFeignApi;

    public List<FindUserByIdRspDTO> findUsersByIds(List<Long> userIds) {
        FindUsersByIdsReqDTO findUsersByIdsReqDTO = FindUsersByIdsReqDTO.builder()
                .ids(userIds)
                .build();

        Response<List<FindUserByIdRspDTO>> response = userFeignApi.findByIds(findUsersByIdsReqDTO);

        if (Objects.isNull(response) || !response.isSuccess() || CollUtil.isEmpty(response.getData())) {
            return null;
        }

        return response.getData();
    }
}
